package com.CST.controller.ys;

import com.CST.common.api.ResultObject;
import com.CST.dto.ys.NumAndYardDTO;
import com.CST.dto.ys.YsBusinessBudgetDTO;
import com.CST.entity.ys.YsAccountDetail;
import com.CST.service.ys.YsManageBudgetService;
import com.CST.vo.ys.YsAccountDetailBusinessOrManageVO;
import com.CST.vo.ys.YsBusinessAccountVO;
import com.CST.vo.ys.YsManageAccountVO;
import com.CST.vo.ys.YsModifyRecordVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 管理-预算执行管理--费用类
 * @author cw
 */
@Api(tags={"管理预算执行管理-费用类"})
@RestController
@RequestMapping("/ysManageBudget")
public class YsManageBudgetController {
    @Autowired
    private YsManageBudgetService ysManageBudgetService;

    @ApiOperation("查询费用类预算")
    @PostMapping("/getManageBudgetList")
    public ResultObject<YsManageAccountVO> getManageBudgetList(@RequestBody YsBusinessBudgetDTO dto){
        return ResultObject.success(ysManageBudgetService.getManageBudgetList(dto));
    }

    @ApiOperation("新增费用类凭证")
    @PostMapping("/insertManageBudget")
    public ResultObject<Boolean> insertManageBudget(@RequestBody YsAccountDetail ysAccountDetail){
        return ResultObject.success(ysManageBudgetService.insertManageBudget(ysAccountDetail));
    }

    @ApiOperation("编辑回显数据")
    @GetMapping("/getInfoByNum/{id}")
    public ResultObject<YsAccountDetailBusinessOrManageVO> getInfoByNum(@PathVariable Integer id){
        return ResultObject.success(ysManageBudgetService.selectInfoByNum(id));
    }

    @ApiOperation("更新费用类凭证")
    @PostMapping("/updateManageAccountByNum")
    public ResultObject<Integer> updateManageAccountByNum(@RequestBody YsAccountDetail ysAccountDetail){
        return ResultObject.success(ysManageBudgetService.updateManageAccountByNum(ysAccountDetail));
    }

    @ApiOperation("删除费用类凭证")
    @GetMapping("/deleteByNum/{id}")
    public ResultObject<Boolean> deleteByNum(@PathVariable Integer id){
        return ResultObject.success(ysManageBudgetService.deleteByNum(id));
    }

    @ApiOperation("发布数据")
    @PostMapping("/releaseData")
    public ResultObject<Boolean> releaseData(@RequestBody YsBusinessBudgetDTO ysBusinessBudgetDto){
        return ResultObject.success(ysManageBudgetService.releaseData(ysBusinessBudgetDto));
    }

    @ApiOperation("查询修订记录")
    @PostMapping("/getModifyRecordList")
    public ResultObject<PageInfo<YsModifyRecordVO>> getModifyRecordList(@RequestBody YsBusinessBudgetDTO ysBusinessBudgetDto){
        return ResultObject.success(ysManageBudgetService.getModifyRecordList(ysBusinessBudgetDto));
    }

    @ApiOperation("撤销")
    @PostMapping("/revokeRecord")
    public ResultObject<Boolean> revokeRecord(@RequestBody NumAndYardDTO dto){
        // 此处传进来的id对应的是修订记录表中的id
        return ResultObject.success(ysManageBudgetService.revokeRecord(dto));
    }

    @ApiOperation("导出")
    @PostMapping("/exportExcelYsManageBudget")
    public void exportExcelYsManageSubject(HttpServletResponse response, @RequestBody YsBusinessBudgetDTO dto) {
        ysManageBudgetService.exportExcelYsManageBudget(response, dto);
    }
}
